import Mock from 'mockjs'
const Random = Mock.Random;

Mock.mock("/api/article", "get", {
  code: 200,
  message: "操作成功",
  'data|5-10': [{
    'id|+1': 1,
    'title': '@ctitle(10, 30)',
    'date': '@date("yyyy-MM-dd")',
    'summary': '@cparagraph(1, 3)',
    'content': '@cparagraph(5, 10)'}]
  })

const articles = Mock.mock({
    'list|1-10': [{
        'id|+1': 1,
        'title': '@ctitle(10, 30)',
        'date': '@date("yyyy-MM-dd")',
        'summary': '@cparagraph(1, 3)',
        'content': '@cparagraph(5, 10)'
    }]
})

Mock.mock("/api/article/list", "get", {
    code: 200,
    message: "操作成功",
    data: articles.list
})

Mock.mock("/\/api\/article\/getarticleById", "get",(req,res) =>{

    const id= req.url.match(/id=(\d+)/)[1];
    const article = articles.list.find(article => article.id == id)
    return {
        code: 200,
        message: "操作成功",
        'data': {
          'id': id,
          'title': '@ctitle(10, 30)',
          'date': '@date("yyyy-MM-dd")',
          'summary': '@cparagraph(1, 3)',
          'content': '@cparagraph(5, 10)'}
    }
})
